<?php
require_once 'Zend/Db/Table/Abstract.php';
class Model_CustomerMapper extends Zend_Db_Table_Abstract
{
	protected $_name='customer';
	protected $_primary='CusID';
	protected $_referenceMap = array (
			'account' => array (
					'columns' => array ('AccID'),
					'refTableClass' => 'Model_AccountMapper',
					'refColumns' => array ('AccID')
			)
	);
	
	public function getCustomer($cusId)
	{
		$row=$this->fetchRow($this->select()->where('CusID=?',$cusId));
	
		$result=new Model_Customer();
	    
		if($row)
		{
			$id=$row->CusID;
			$accId=$row->AccID;
			$address=$row->Address;
			$accMapper=new Model_AccountMapper();
			$account=$accMapper->getAccount($accId);
			$customer=new Model_Customer();
			$customer->setId($id)->setAccount($account)->setAddress($address);
			$result=$customer;
		}
		else{
			$result->setId(-1);
		}
		return $result;
	}
	
	public function getCustomerByAccId($AccId)
	{
		$row=$this->fetchRow($this->select()->where('AccID=?',$AccId));
	
		$result=new Model_Customer();
		 
		if($row)
		{
			$id=$row->CusID;
			$accId=$row->AccID;
			$address=$row->Address;
			$accMapper=new Model_AccountMapper();
			$account=$accMapper->getAccount($accId);
			$customer=new Model_Customer();
			$customer->setId($id)->setAccount($account)->setAddress($address);
			$result=$customer;
		}
		else{
			$result->setId(-1);
		}
		return $result;
	}
	
	
}